/**
 * @Description: WoShop商城
 * @Author: Parker
 * @Copyright: 武汉一一零七科技有限公司©版权所有
 * @Link: www.wo-shop.net
 * @Contact: QQ:2487937004
 */
import Vue from "vue";
import App from "./App";
import api from "./api";
import * as utils from "./utils";
import store from "./store";
import mpvuePicker from "./components/mpvue-picker/mpvuePicker.vue";
import uView from "uview-ui";
import loadMore from "./components/uni-load-more.vue";
import popupLayer from "./components/popup-layer.vue";
import liveAnimation from "./components/liveAnimation";
import '@/utils/registerBaseStyle'
import jump from '@/utils/globalJump'

import "@/static/css/index.less";

// 注册所有全局组件
// register(require.context('./components/widgets', true, /.vue/))
/**
 * 注册对应包下所有组件
 * @param {*} path 包路径
 */
// function register(context) {
//   console.log({context})
//   context.keys().forEach(cnt => {
//     const component = context(cnt)
//     let ctrl = component.default || component
//     let a = ctrl.name || ''
//     let b = ctrl
//     // 注册组件
//     Vue.component(a, b)
//   })
// }

Vue.prototype.$jump = jump
import {
	APPNAME,
	STATICURL,
	SERVERTAPI,
	LIVESOCKET
} from "./config/index.js";
import im from "./utils/socket"
//多语言
import messages from './locale/index'
let i18nConfig = {
	locale: uni.getLocale(),
	messages
}
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n(i18nConfig)

Vue.config.productionTip = false;
Vue.use(uView);

Vue.component("mpvue-picker", mpvuePicker);
Vue.component("popup-layer", popupLayer);
Vue.component("liveAnimation", liveAnimation);
Vue.component("loadMore", loadMore);

App.mpType = "app";

// 返回上级页面
Vue.prototype.getback = function() {
	uni.navigateBack({
		delta: 1,
	});
};

Vue.prototype.getnav = function(url) {
	uni.navigateTo({
		url: url,
	});
};

Vue.prototype.statusMath = function(that) {
	setTimeout(() => {
		that.valueStatus = Math.random();
	}, 100);
};

// 注册全局过滤器
import '@/utils/filters.js'
Vue.filter('defaultValue', value => {
	if (!value) return 0;
	return value
})

Vue.filter('tagType', value => {
	const list = ['自营', '秒杀', '团购', '拼团']
	return list[+value]
})

Vue.filter('currency', value => {
	return ''
})

Vue.prototype.$store = store;
Vue.prototype.$navigateTo = utils.navigateTo;
Vue.prototype.im = im; //绑定全局的socket链接事件  分别在登录时和 APP Luanch时触发
Vue.prototype.$showModal = utils.showModal;
Vue.prototype.$http = api;
Vue.prototype.$Dialog = utils.Dialog;
Vue.prototype.$loading = utils.showLoading;
Vue.prototype.$hideLoading = utils.hideLoading;
Vue.prototype.$toast = utils.showToast;
Vue.prototype.$formatDateTime = utils.formatDateTime;
Vue.prototype.$formatSeconds = utils.formatSeconds;
Vue.prototype.$copy = utils.copy;
Vue.prototype.$AppName = APPNAME;
Vue.prototype.$liveSocket = LIVESOCKET;
Vue.prototype.$baseUrl = SERVERTAPI;
Vue.prototype.$imgGoodsNullUrl = STATICURL + "/static/images/img/cartinfo.png";
Vue.prototype.STATICURL = STATICURL; // 存放在腾讯云COS存储上的前端静态资源文件地址

// 引入uView对小程序分享的mixin封装
let mpShare = require('uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare)

const app = new Vue({
	i18n,
	store,
	...App,
});

app.$mount();
